package com.yenlien.traceyun.plant.controller;

import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.plant.entity.ColdProduct;
import com.yenlien.traceyun.plant.service.ColdProductService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date 2022/8/30
 * @Author jiaLong
 * @Descript
 */
@RestController
@RequestMapping("/coldProduct")
public class ColdProductController extends BaseController {

    @Autowired
    private ColdProductService coldProductService;


    @PostMapping(value = "/save")
    public Object save(@RequestBody ColdProduct coldProduct)  {
        return success(coldProductService.save(coldProduct));
    }

    @GetMapping(value = "/delById/{id}")
    public Object delById(@PathVariable("id") String id)  {
        coldProductService.delById(id);
        return success("success");
    }


    @PostMapping(value = "/findByList")
    public Object findByList(@RequestBody ColdProduct coldProduct) {
        if(StringUtils.isBlank(coldProduct.getCompanyId())){
            coldProduct.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        }
        return success(coldProductService.findByList(coldProduct));
    }

    @PostMapping(value = "/findListNotPage")
    public Object findListNotPage(@RequestBody ColdProduct coldProduct) {
        if(StringUtils.isBlank(coldProduct.getCompanyId())){
            coldProduct.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        }
        return success(coldProductService.findListNotPage(coldProduct));
    }

    // 不根据companyId进行数据隔离
    @PostMapping(value = "/findNotPageComp")
    public Object findNotPageComp(@RequestBody ColdProduct coldProduct) {
        return success(coldProductService.findListNotPage(coldProduct));
    }




}
